package com.afkt.app.slice;

import com.afkt.app.ResourceTable;
import com.afkt.app.utils.*;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Button;
import ohos.agp.components.Component;


public class MainAbilitySlice extends AbilitySlice {

    private Button btn_my_apps;
    private Button btn_system_apps;
    private Button btn_Phone_Info;
    private Button btn_Screen_Info;
    private Button btn_Scanning_Apk;
    private Button btn_Setting;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);

        btn_my_apps = (Button) findComponentById(ResourceTable.Id_btn_my_apps);
        btn_system_apps = (Button) findComponentById(ResourceTable.Id_btn_system_apps);
        btn_Phone_Info = (Button) findComponentById(ResourceTable.Id_btn_Phone_Info);
        btn_Screen_Info = (Button) findComponentById(ResourceTable.Id_btn_Screen_Info);
        btn_Scanning_Apk = (Button) findComponentById(ResourceTable.Id_btn_Scanning_Apk);
        btn_Setting = (Button) findComponentById(ResourceTable.Id_btn_Setting);

        //我的应用（My Apps）
        btn_my_apps.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                startAbility(OpenAppSetting.openAppSet());
            }
        });

        //系统应用（System apps）
        btn_system_apps.setClickedListener(component -> startAbility(OpenSystemApps.openAppSet()));

        //手机信息（Phone Info）
        if (btn_Phone_Info != null) {

            btn_Phone_Info.setClickedListener(component -> {
                present(new PhoneInfoAbilitySlice(), new Intent());
/*                Intent secondIntent = new Intent();
                // 指定待启动FA的bundleName和abilityName
                Operation operation = new Intent.OperationBuilder()
                        .withBundleName(getBundleName())
                        .withAbilityName(getBundleName()+".PhoneInfoAbility")
                        .build();
                secondIntent.setOperation(operation);
                // 通过AbilitySlice的startAbility接口实现启动另一个页面
                startAbility(secondIntent);*/
            });
        }

        //屏幕信息（Screen Info）
        if (btn_Screen_Info != null) {

            btn_Screen_Info.setClickedListener(component -> {
                present(new ScreenInfoAbilitySlice(), new Intent());
            });
        }


        //扫描Apk（Scanning Apk）
        btn_Scanning_Apk.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                startAbility(OpenScanningApk.openAppSet());
            }
        });

        //设置（Setting）
        btn_Setting.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                startAbility(OpenSetting.openAppSet());
            }
        });

    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
